﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MedicalSystems
{
    public class Record
    {
        private const string defaultDate = "01-Jan-01 00:00:00";

        private string FirstName { get; set; }
        private string LastName { get; set; }
        public string FullName { get { return this.LastName + "," + this.FirstName; } }
        public string Gender { get; set; }
        public string Parameter { get; set; }
        public string ParamValue { get; set; }
        public string Unit { get; set; }
        public DateTime startTime { get; set; }
        public DateTime finishTime { get; set; }
        public DateTime txnStartTime { get; set; }
        public DateTime txnFinishTime { get; set; }
        private bool hasFinish;

        public Record(string first, string last,string sex, string param, string val,string unit, string start, string finish, string txnSart)
        {
            this.Gender = sex;
            this.FirstName = first;
            this.LastName = last;
            this.Parameter = param;
            this.ParamValue = val;
            this.Unit = unit;
            this.startTime = Convert.ToDateTime(start);
            this.finishTime = Convert.ToDateTime(finish);
            this.txnStartTime = Convert.ToDateTime(txnSart);
            this.hasFinish = false;
        }

        public Record(string first, string last,string sex ,string param, string val, string unit, string start, string finish, string txnSart, string txnfinish)
        {
            this.Gender = sex;
            this.FirstName = first;
            this.LastName = last;
            this.Parameter = param;
            this.ParamValue = val;
            this.Unit = unit;
            this.startTime = Convert.ToDateTime(start);
            this.finishTime = Convert.ToDateTime(finish);
            this.txnStartTime = Convert.ToDateTime(txnSart);
            if (txnfinish != null && txnfinish != "")
            {
                this.txnFinishTime = Convert.ToDateTime(txnfinish);
                this.hasFinish = true;
            }
            else
            {
                this.hasFinish = false;
            }
        }

        public Record(Record r)
        {
            this.FirstName = r.FirstName;
            this.LastName = r.LastName;
            this.Gender = r.Gender;
            this.Parameter = r.Parameter;
            this.ParamValue = r.ParamValue;
            this.Unit = r.Unit;
            this.startTime = r.startTime;
            this.finishTime = r.finishTime;
            this.txnStartTime = r.txnStartTime;
            this.txnFinishTime = r.txnFinishTime;
            this.hasFinish = r.hasFinish;
        }

        public void setValueByIndex(string val, int index)
        {
            try
            {
                switch (index)
                {
                    case 1:
                        if (val == "M" || val == "F")
                        {
                            this.Gender = val;
                        }
                        break;
                    case 2:
                        this.Parameter = val;
                        break;
                    case 3:
                        this.ParamValue = val;
                        break;
                    case 4:
                        this.Unit = val;
                        break;
                    case 5:
                        this.startTime = Convert.ToDateTime(val);
                        break;
                    case 6:
                        this.finishTime = Convert.ToDateTime(val);
                        break;
                    case 7:
                        this.txnStartTime = Convert.ToDateTime(val);
                        break;
                    case 8:
                        this.txnFinishTime = Convert.ToDateTime(val);
                        this.hasFinish = true;
                        break;
                    default:
                        break;
                }
            }
            catch (Exception) { }
        }

        public bool hasHinishTXN()
        {
            return this.hasFinish;
        }

        public override string ToString()
        {
            string ans = this.FirstName + "\t" + this.LastName + "\t" +this.Gender + "\t" + this.Parameter + "\t" + this.ParamValue + "\t" + this.Unit + "\t" + this.startTime + "\t"
                + this.finishTime + "\t" + this.txnStartTime + "\t";

            if (this.txnFinishTime.ToString() != Convert.ToDateTime(defaultDate).ToString()) ans += this.txnFinishTime;
            return ans;
        }
    }
}
